import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.AirlineReservationServiceProxy;
import bean.Journey;
import constants.AirlineReservationServiceConstants;


public class ViewFlightsByDateServlet extends HttpServlet{
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	
		AirlineReservationServiceProxy proxy = new AirlineReservationServiceProxy(
				AirlineReservationServiceConstants.SERVICE_URL);
	
		
		Journey[] journey = proxy.viewFlightsByDate();
		
		List<Journey> lstJourney = new ArrayList<Journey>();
		
		if(journey!=null){
			lstJourney = Arrays.asList(journey);
		}
		
		req.setAttribute("lstFlights",lstJourney);
		
		req.getRequestDispatcher("viewFlightsByDate.jsp").forward(req, resp);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

}
